
/*******************************************************************************
 * 
 * Designed by : A. Augustine Joseph Starting Date : 11-01-2003 Last modified by :
 * A. Augustine Joseph Last modified Date : 17-01-2003 Total number of Class : 1
 * Total number of Methods : 3 Class Description : This is the main class for
 * designing the table components
 *  
 ******************************************************************************/

package com.jjprojects.earutility;
import java.awt.Color;
import java.awt.Font;

import javax.swing.JTable;
import javax.swing.table.DefaultTableColumnModel;
import javax.swing.table.JTableHeader;
import javax.swing.table.TableColumn;
import javax.swing.table.TableColumnModel;

public class TableDesigner
{
    //Simply Constructor
    public TableDesigner()
    {
    }

    /***************************************************************************
     * 
     * Method Description : This is used for designing the Tables header Method
     * Parameter : TableColumnModel Method Parameter Value : TableColumnModel
     * Method Return Type : JTableHeader Use of Return Value : JTableHeader
     *  
     **************************************************************************/
    public static JTableHeader createTableHeader(TableColumnModel tcm)
    {
        Font font = new Font("Sans Serif", Font.PLAIN, 12);
        JTableHeader jth = new JTableHeader(tcm);
        jth.setReorderingAllowed(false);
        jth.setResizingAllowed(true);
        jth.setBackground(Color.BLACK);
        jth.setForeground(Color.BLUE);
        jth.setFont(font);
        jth.setVisible(true);
        jth.setBorder(null);
        jth.resizeAndRepaint();
        jth.validate();
        return jth;
    }

    /***************************************************************************
     * 
     * Method Description : This is used for designing the Tables
     * 
     * Method Parameter1 : SubTable Method Parameter1 Value : A Class with
     * extends AbstractTableModal Method Parameter2 : TableColumnModel Method
     * Parameter2 Value : A TableColumnModel class used for designing the table
     * Method Parameter3 : JTableHeader Method Parameter3 Value : A TableHeader
     * class used for designing the table Method Parameter4 : int Method
     * Parameter4 Value : Resizing mode of the table Method Parameter5 : int
     * Method Parameter5 Value : Row height of the table Method Parameter6 :
     * boolean Method Parameter6 Value : Set weather the grid is show or not for
     * the table Method Parameter7 : boolean Method Parameter7 Value : Set
     * weather cell selection is allowed or not for the table Method Parameter8 :
     * boolean Method Parameter8 Value : Set weather row selection is allowed or
     * not for the table Method Parameter9 : int Method Parameter9 Value : Set
     * the Row Selection mode
     * 
     * Method Return Type : JTable Use of Return Value : The designed table
     *  
     **************************************************************************/
    public static JTable createTable(CustomAbstractTableModel stm,
            TableColumnModel tm, JTableHeader jth, int rsz, int rh,
            boolean sgr, boolean csel, boolean rsel, int smd)
    {
        Font font = new Font("Sans Serif", Font.PLAIN, 11);
        JTable tab = new JTable(stm, tm);
        tab.setTableHeader(jth);
        tab.setFont(font);
        tab.setAutoResizeMode(rsz);
        tab.setRowHeight(rh);
        tab.setShowGrid(sgr);
        tab.setCellSelectionEnabled(csel);
        tab.setRowSelectionAllowed(rsel);
        tab.setSelectionMode(smd);
        return tab;
    }
    
//  New added for adding 1 column table
    public static TableColumnModel createColumnModelForOneRow(TableColumn tc1)
    {
        TableColumnModel tcm = new DefaultTableColumnModel();
        tcm.addColumn(tc1);
        tcm.setColumnSelectionAllowed(true);
        return tcm;
    }

    //New added for adding 2 column table
    public static TableColumnModel createColumnModelForThreeRow(TableColumn tc1,
            TableColumn tc2, TableColumn tc3)
    {
        TableColumnModel tcm = new DefaultTableColumnModel();
        tcm.addColumn(tc1);
        tcm.addColumn(tc2);
        tcm.addColumn(tc3);
        tcm.setColumnSelectionAllowed(true);
        return tcm;
    }
    
    /***************************************************************************
     * 
     * Method Description : This is used for designing the Table's Column model
     * 
     * Method Parameter1 : TableColumn Method Parameter1 Value : First Table
     * Column Method Parameter2 : TableColumn Method Parameter2 Value : Second
     * Table Column Method Parameter3 : TableColumn Method Parameter3 Value :
     * Third Table Column Method Parameter4 : TableColumn Method Parameter4
     * Value : Fourth Table Column Method Parameter5 : TableColumn Method
     * Parameter5 Value : Fifth Table Column Method Parameter6 : TableColumn
     * Method Parameter6 Value : Sixth Table Column Method Parameter7 :
     * TableColumn Method Parameter7 Value : Seventh Table Column Method
     * Parameter8 : TableColumn Method Parameter8 Value : Eight Table Column
     * 
     * Method Return Type : TableColumnModel Use of Return Value :
     * TableColumnModel
     *  
     **************************************************************************/
    public static TableColumnModel createColumnModel(TableColumn tc,
            TableColumn tc1, TableColumn tc2, TableColumn tc3, TableColumn tc4,
            TableColumn tc5, TableColumn tc6, TableColumn tc7)
    {
        TableColumnModel tcm = new DefaultTableColumnModel();
        tcm.addColumn(tc);
        tcm.addColumn(tc1);
        tcm.addColumn(tc2);
        tcm.addColumn(tc3);
        tcm.addColumn(tc4);
        tcm.addColumn(tc5);
        tcm.addColumn(tc6);
        tcm.addColumn(tc7);
        tcm.setColumnSelectionAllowed(true);
        return tcm;
    }

    /***************************************************************************
     * 
     * Method Description : This is used for designing the Table's Column
     * 
     * Method Parameter1 : int Method Parameter1 Value : The Column number
     * Method Parameter2 : int Method Parameter2 Value : The width of the column
     * Method Parameter3 : String Method Parameter3 Value : Column Value
     * 
     * Method Return Type : TableColumn Use of Return Value : TableColumn
     *  
     **************************************************************************/
    public static TableColumn createColumn(int index, int width, String val)
    {
        TableColumn tbc = new TableColumn(index, width);
        tbc.setHeaderValue(val);
        return tbc;
    }
}